package com.neuedu.autosale.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.neuedu.autosale.util.Const;

public class LoginInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String path = request.getServletPath();
		if (path.matches(Const.NO_INTERCEPTOR_PATH)) {
			System.out.println("----------直接通过+++++++++++++");
			return true;
		} else {
			// 拦截
			Object admin = request.getSession().getAttribute(Const.SESSION_EMP);
			if (admin == null) {
				response.sendRedirect(request.getContextPath() + "/emp/login");
				System.out.println("登录失败返回登录页面");
				return false;
			}

			System.out.println("=============登陆成功=======================");
			return true;
		}
	}
}
